package com.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.hibernate.HibernateSessionFactory;
import com.model.Administrator;


public class AdministratorDao {
	public Administrator login(Administrator admin) {
		Session session = HibernateSessionFactory.getSession();
		try {
			Administrator a = null;
			session.beginTransaction();
			String queryString = "from Administrator where uname=? and upwd=?";
			Query query = session.createQuery(queryString);
			query.setParameter(0, admin.getUname());
			query.setParameter(1, admin.getUpwd());
			a = (Administrator) query.uniqueResult();
			session.getTransaction().commit();
			return a;
		} catch (Exception e) {
			session.getTransaction().rollback();
			e.printStackTrace();
			return null;
			// TODO: handle exception
		} finally {
			HibernateSessionFactory.closeSession();
		}
	}
}
